package middlewares

import (
	"github.com/gofiber/fiber/v2"

	"main/src/models"
)

func CheckRegRole(validRoles []string) func(*fiber.Ctx) error {
	return func(c *fiber.Ctx) error {
		var user models.User
		if err := c.BodyParser(&user); err != nil {
			return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request"})
		}
		role := user.Role

		for _, validRole := range validRoles {
			if role == validRole {
				return c.Next()
			}
		}

		return c.SendStatus(fiber.StatusBadRequest)
	}
}
